//FirstView Component Constructor
function FirstView() {
	//create object instance, a parasitic subclass of Observable
	var self = Ti.UI.createView({
		layout:"vertical"
	});
	
	if(Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){ 
		alert('Please check your internet connection');
	}

	///////////////////////
	var viewTop = Ti.UI.createView({
		height:150,
		layout:'horizontal'
	});
	
	var sapLogo = Ti.UI.createImageView({
		image:'/images/SAPBOne.png',
		width:'auto',
		left:'10%'
	});
	var logo = Ti.UI.createImageView({
  		image:'/images/ABLogo.png',
  		width:'auto'
	});	
	logo.left = sapLogo.left + sapLogo.width;
	
	//////////////////////
	viewTop.add(sapLogo);
	viewTop.add(logo);
	
	
	var viewCompany = Ti.UI.createView({
		height:65,
		layout:"horizontal"
	});
	
	var viewUsername = Ti.UI.createView({
		height:65,
		layout:"horizontal"
	});
	
	var viewPassword = Ti.UI.createView({
		height:65,
		layout:"horizontal"
	});
	
	var viewCheckbox = Ti.UI.createView({
		height:65
	});
	
	var viewButton = Ti.UI.createView({
		height:65
	});
	
	
	var lbUsername = Ti.UI.createLabel({
		text:"Username",
		left:'30%'
	});
	var txtUsername = Ti.UI.createTextField({
		width:200,
		font: {fontSize: 14}
	});
	txtUsername.left = lbUsername.left + 150;
	
	
	var lbPassword = Ti.UI.createLabel({
		text:"Password",
		left:'30%'
	});
	var txtPassword = Ti.UI.createTextField({
		width:200,
		passwordMask:true,
		font: {fontSize: 14}
	});
	txtPassword.left = lbPassword.left + 150;
	
	var lbCompany = Ti.UI.createLabel({
		text:"Company",
		left:'30%'
	});
	var lbOnlinemode = Ti.UI.createLabel({
		text:"Online mode",
		left:'30%'
	});
	
	var picker = Ti.UI.createPicker({ 
		width:200,
		height:'50',
		font: {fontSize: 12}
	}); 
	picker.left = lbCompany.left + 150;
	
	var btnLogin = Ti.UI.createButton({
		title: "Login",
		width:'auto',
		height:'auto',
		font:{fontSize:14}
	});
	btnLogin.addEventListener('click',function(e)
	{
		
		//var emp = require("/ui/common/Employee");
		//var win = new emp();
		//win.open({animated:true});
		//var emp = require("/ui/common/FeedExp");
		var emp = require("/ui/common/Favorite");
		var win = new emp();
		win.open({animated:true});
	});
	
	var chkOnlineMode = Ti.UI.createSwitch({
		  style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
		  textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,
		  value:true,
		  width:'auto'
	});
	
	var data = []; 
	
	var xhr = Titanium.Network.createHTTPClient();
	xhr.onload = function() {
		
			var xmlDoc = Ti.XML.parseString(this.responseText).documentElement;
	   		var xlinestatus = xmlDoc.getElementsByTagName('Table');
			
			for (i = 0; i < xlinestatus.length; i++) {
			var theItem = xlinestatus.item(i);
				data.push(Titanium.UI.createPickerRow({title:theItem.getElementsByTagName("CompanyDB").item(0).text})); 
			//alert(" Line: " + );
			}
			picker.add(data);
		};
	xhr.open('GET', 'http://192.168.1.82:83/MasterData.asmx/GetCompanyList?UserID=duccv');
	xhr.send({});

	viewCompany.add(lbCompany);
	viewCompany.add(picker);
	
	viewUsername.add(lbUsername);
	viewUsername.add(txtUsername);
	
	viewPassword.add(lbPassword);
	viewPassword.add(txtPassword);
	
	viewCheckbox.add(lbOnlinemode);
	viewCheckbox.add(chkOnlineMode);
	
	viewButton.add(btnLogin);
	
	self.add(viewTop);
	self.add(viewCompany);
	self.add(viewUsername);
	self.add(viewPassword);
	self.add(viewCheckbox);
	self.add(viewButton);
	
	return self;
}

module.exports = FirstView;
